package logic

import (
	"context"
	"goods/goodsclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateGoodsLogic {
	return &CreateGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateGoodsLogic) CreateGoods(req *types.CreateGoodsrequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	goods, err := l.svcCtx.GoodsSrv.CreateGoods(l.ctx, &goodsclient.CreateGoodsRequest{
		GoodsTitle:  req.GoodsTitle,
		GoodsCover:  req.GoodsCover,
		GoodsPrice:  float32(req.GoodsPrice),
		GoodsSize:   req.GoodsSize,
		GoodsStock:  int64(req.GoodsStock),
		CheckStatus: int64(req.CheckStatus),
		Status:      int64(req.Status),
	})
	if err != nil {
		return &types.Response{
			Msg:  err.Error(),
			Code: 500,
			Data: nil,
		}, nil
	}
	return &types.Response{
		Msg:  "商品创建成功",
		Code: 200,
		Data: goods,
	}, nil
}
